/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.pos.ui.beans;

import com.pos.domain.Vendor;
import com.pos.services.BaseService;
import java.io.Serializable;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.enterprise.context.Conversation;
import javax.enterprise.context.ConversationScoped;
import javax.inject.Inject;
import javax.inject.Named;

/**
 *
 * @author Dipendra
 */
@Named("supplierBean")
@ConversationScoped
public class SupplierBean implements Serializable {

    @Inject
    private transient BaseService baseService;
    @Inject
    private Conversation conversation;
    private Vendor vendor;
    private boolean editMode;

    @PostConstruct
    public void reset() {
        this.vendor = new Vendor();
    }

    public List<Vendor> getSuppliers() {
        return baseService.findAllSupplier();
    }

    public Vendor getSupplier() {
        return this.vendor;
    }

    public void createNewSupplier() {
        this.vendor = new Vendor();
        setEditMode(true);
    }

    public void setEditMode(boolean editMode) {
        this.editMode = editMode;
    }

    public boolean isEditMode() {
        return this.editMode;
    }

    public void save() {
        this.baseService.saveSupplier(this.vendor);
        this.reset();
        setEditMode(false);
    }

    public String delete() {
        return "";
    }

    public void edit(Object id) {
        Vendor supplier = baseService.findSupplierById(id);
        if (supplier != null) {
            this.vendor = supplier;
        }
        setEditMode(true);
    }

    public Vendor findVendor(long id) {
        return baseService.findSupplierById(id);
    }
}
